<template>
	<view class="">

		<view class="body">
			<view class="top-container">
				<uni-list :border="false">
					<!-- <uni-list-item :border="false" title="执行者" :rightText="userInfo.name" /> -->
					<uni-list-item :border="false" title="单据编号" :rightText="header.billNo" />
					<uni-list-item :border="false" title="模具名称" :rightText="header.materialName" />
					<uni-list-item :border="false" title="模具编码" :rightText="header.materialNo" />
					<uni-list-item :border="false" title="仓位" :rightText="header.locationNo" />

					<uni-list-item :border="false" title="日期">
						<template v-slot:footer>
							<uni-dateformat :date="header.createTime" format="yyyy年MM月dd日">
							</uni-dateformat>
						</template>
					</uni-list-item>
					<uni-list-item>
						<template v-slot:header>
							<text style="color: #333; font-weight: bold;">维修类型</text>
						</template>
						<template v-slot:footer>
							<uni-tag :text="statusText" :type="statusType"
								custom-style="color: #333; font-weight: bold;">

							</uni-tag>
						</template>
					</uni-list-item>

				</uni-list>

				<view class="form-row">
					<text class="form-label">维修人员</text>
					<view class="form-value">
						<input v-model="header.repairName" placeholder="请输入维修人员" class="uni-input"
							style="color: #333; font-size: 14px; border: 1px solid #ccc; background-color: #fff; border-radius: 4px; padding: 6rpx 12rpx; width: 100%;" />
					</view>
				</view>

				<view class="form-row">
					<text class="form-label">维修开始时间</text>
					<view class="form-value">
						<uni-datetime-picker v-model="header.repairStartTime" type="datetime" placeholder="请选择开始时间" />
					</view>
				</view>

				<view class="form-row">
					<text class="form-label">维修结束时间</text>
					<view class="form-value">
						<uni-datetime-picker v-model="header.repairEndTime" type="datetime" placeholder="请选择结束时间" />
					</view>
				</view>

				<view class="form-row" >
				  <text class="form-label">模具状态</text>
				  <view class="form-value">
				    <uni-data-select
					@change="change()"  
				      v-model="header.repairType"
				      :localdata="repairOptionsAll[this.header.category]"
				      placeholder="请选维修类别"
				      :clear="false"
				      custom-style="color: #333; font-size: 14px; border: 1px solid #ccc; background-color: #fff; border-radius: 4px; padding: 6rpx 12rpx; width: 100%;"
				    />
				  </view>
				</view>

				<view class="form-row">
					<text class="form-label">备注</text>
					<view class="form-value">
						<textarea v-model="header.remark" placeholder="请输入备注信息"
							style="color: #333; font-size: 14px; border: 1px solid #ccc; background-color: #fff; border-radius: 4px; padding: 12rpx; width: 100%; min-height: 100rpx;"></textarea>
					</view>
				</view>


			</view>



		</view>
		<!--  底部按钮  -->
		<view class="footerPanel">
			<view class="footerPanel_body">

				<button v-if="header.status  == 1"  @click="auditMoldMain" class="footerBtn save"><i
						class="iconfont icon-duihao btn_icon"></i>保存
				</button>

			</view>
		</view>


	</view>
</template>

<script>
	import uniTransition from 'uni_modules/uni-transition/components/uni-transition/uni-transition.vue';
	import uniEmptyInfo from "../../vBase/components/uni-empty-info/uni-empty-info.vue"
	import {
		getMoldMainDetail,
		moldInspectPickmold,
		auditMoldMain
	} from '@/utils/api.js'



	export default {
		components: {
			uniEmptyInfo
		},
		data() {
			return {
	
				billNo: '',
				loading: true,
				header: {
					status: 0,
					category: 0
				},
				detail: [],

				moldData: {},
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#FF4E74'
					}
				}],
				repairOptionsAll: {
				        1: [
				          { value: '全包改半包', text: '全包改半包' },
				          { value: '型体填退刀槽', text: '型体填退刀槽' },
				          { value: '单层改双层', text: '单层改双层' },
				          { value: '修改余量', text: '修改余量' },
				          { value: '其它', text: '其它' }
				        ],
				        2: [
				          { value: '修补浇道', text: '修补浇道' },
				          { value: '更换排气塞', text: '更换排气塞' },
				          { value: '调整顶杆', text: '调整顶杆' },
				          { value: '更换顶板', text: '更换顶板' },
				          { value: '更换火板', text: '更换火板' },
				          { value: '入水方式变更', text: '入水方式变更' },
				          { value: '调整排气圈', text: '调整排气圈' },
				          { value: '修补型体模', text: '修补型体模' },
				          { value: '修补砂芯模', text: '修补砂芯模' },
				          { value: '其它', text: '其它' }
				        ]
				      }
			}
		},
		methods: {
			
			change(){
				// console.log(this.header.repairType)
			
			},
			//审核模具维修单
			auditMoldMain() {
				//如果维修类别是大修，必须输入入库单号
				// if (this.header.category == 1 ){
				// 	if (!this.header.inStockNo || this.header.inStockNo.trim() === ''){
				// 		uni.showToast({
				// 			title: '入库单号不能为空',
				// 			icon: 'none'
				// 		})
				// 	}
				// 	return;
				// }
				let _this = this;
				uni.showModal({
					title: '提示',
					content: '是否确认保存',
					success(res) {
						if (res.confirm) {
							auditMoldMain(_this.header).then(result => {
								if (result.data.data) {
									uni.showToast({
										title: '审核成功',
										icon: 'none'
									})
								}
								setTimeout(() => {
									uni.navigateBack({
										delta: 1,
										success() {
											uni.$emit('update', {
												msg: '页面刷新'
											});
										}
									})
								}, 2000)

							})

						}
					}
				})
			},


			// 获取详情数据
			initData() {
				getMoldMainDetail({
					billNo: this.billNo
				}).then(res => {
					if (res.statusCode == 200) {
						this.header = res.data.data.data
					}
				})

			}
		},
		computed: {
			statusText() {
				if (this.header.category === 1) return '大修';
				if (this.header.category === 2) return '小修';

				return '';
			},
			statusType() {
				const status = Number(this.header.category)
				if (status === 1) return 'warning'
				if (status === 2) return 'primary'
				return 'success'
			}
		},
		watch: {
			userInfo() {

			}
		},
		mounted() {
			this.initData()

		},
		onLoad(e) {
			this.billNo = e.billNo

		}
	}
</script>

<style lang="scss" scoped>
	@import "../../static/css/common";

	.form-row {
		display: flex;
		flex-direction: row;
		align-items: flex-start;
		padding: 20rpx 16rpx;
		border-bottom: 1px solid #eee;
		flex-wrap: wrap;
	}

	.form-label {
		width: 180rpx;
		font-size: 28rpx;
		color: #333;
		font-weight: bold;
		padding-top: 10rpx;
	}

	.form-value {
		flex: 1;
		width: calc(100% - 180rpx); // 避免超出边框
		box-sizing: border-box;
	}

	.uni-input,
	textarea {
		width: 100%;
		font-size: 28rpx;
		color: #333;
		border: 1px solid #ccc;
		background-color: #fff;
		border-radius: 8rpx;
		padding: 12rpx 20rpx;
		box-sizing: border-box;
	}
</style>
